package com.gruppsex.trainingdairy;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class ProfileActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		overridePendingTransition(R.anim.fadein, R.anim.fadeout);
		setContentView(R.layout.profile);
	}

	public void buttonClicked(View v) {
		boolean didItWork = true;
		DataBaseHelper dbHelper = new DataBaseHelper(ProfileActivity.this);
		EditText etName = (EditText) findViewById(R.id.editTextName);
		EditText etAge = (EditText) findViewById(R.id.editTextAge);
		EditText etWeight = (EditText) findViewById(R.id.editTextWeight);
		EditText etLength = (EditText) findViewById(R.id.editTextLength);

		switch (v.getId()) {
		case R.id.buttonSave:

			try {
				String name = etName.getText().toString();
				String age = etAge.getText().toString();
				String weight = etWeight.getText().toString();
				String length = etLength.getText().toString();
				dbHelper.openDataBase();
				dbHelper.createProfileEntry(name, age, weight, length);
				dbHelper.close();

			} catch (Exception e) {

			} finally {
				if (didItWork) {
					Dialog d = new Dialog(this);
					d.setTitle("New profile");
					TextView tv = new TextView(this);
					tv.setText("Your new profile has been created/or saved!");
					d.setContentView(tv);
					d.show();
					Intent myIntent = new Intent(v.getContext(), StartActivity.class);
					
					v.getContext().startActivity(myIntent);
					ProfileActivity.this.finish();
				}
			}
			break;
		}
	}
}
